<template>
  <div class="bpr2-bg">
    <div class="co-title">
      <div class="co-title-name">
        <img src="@/assets/cockpit/bpr2-title.png" alt="" />
      </div>
      <div class="co-title-right">
        <div class="co-title-breathe"><i></i><i></i><i></i><i></i><i></i><i></i></div>
      </div>
    </div>
    <div class="bpl-container">
      <!-- <div class="bpr2-title">本年度新增建设项目总数：<span v-if="infoData.project">{{ infoData.project.totalQuantity }}</span>个</div> -->
      <div class="bpr2-chartbox">
        <div class="bpr2-chart-bg"></div>
        <div class="box-chart" id="boxChart"></div>
        <ul class="box-legend">
          <li v-for="(item, index) in rankOrigin" :key="index">{{ item.typeName }}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import Highcharts from 'highcharts/highstock'
import HighchartsMore from 'highcharts/highcharts-more'
import HighchartsDrilldown from 'highcharts/modules/drilldown'
import Highcharts3D from 'highcharts/highcharts-3d'
HighchartsMore(Highcharts)
HighchartsDrilldown(Highcharts)
Highcharts3D(Highcharts)

@Component({
  name: 'BprItem2',
  components: {}
})
export default class BprItem2 extends Vue {
  @Prop({ default: {} }) infoData!: any
  private chart: any
  private rankOrigin: any[] = [
    {
      typeName: '选址预审',
      quantity: 41
    },
    {
      typeName: '用地规划许可',
      quantity: 83
    },
    {
      typeName: '工程规划许可',
      quantity: 153
    },
    {
      typeName: '竣工验收',
      quantity: 75
    }
  ]
  private rankData: any[] = []
  private options: any = {
    credits: {
      enabled: false
    },
    chart: {
      type: 'pie',
      plotBackgroundColor: null,
      plotBorderWidth: null,
      plotShadow: false,
      backgroundColor: null,
      options3d: {
        enabled: true,
        alpha: 60
      }
    },
    title: {
      text: null
    },
    subtitle: {
      text: null
    },
    plotOptions: {
      pie: {
        size: 110,
        innerSize: 70,
        depth: 20,
        dataLabels: {
          //数据标签
          enabled: true, //是否启用
          format: '{y}',
          distance: '-10%'
        },
        showInLegend: true
      }
    },
    legend: {
      enabled: false
      // layout: 'vertical',
      // align: 'right',
      // verticalAlign: 'middle',
      // floating: true,
      // symbolwidth: 6,
      // symbolHeight: 6,
      // itemStyle: {
      //   fontSize: '12px',
      //   color: '#fff',
      //   fontWeight: 'normal'
      // },
      // itemHoverStyle: {
      //   color: '#00EAFF'
      // }
    },
    series: [
      {
        name: '数量',
        center: ['24%', '40%'],
        colors: ['#00EAFF', '#6DFFD6', '#FFCF40', '#0095FF', '#00FFAA', '#006AFF'],
        data: []
      }
    ]
  }
  // @Watch('infoData', { deep: true, immediate: true }) dataChange(val: any) {
  //   if(val && val.proRanks) {
  //     this.rankOrigin = val.proRanks
  //     if(this.rankOrigin.length > 0) {
  //       this.handleRank()
  //     }
  //   }
  // }
  mounted() {
    this.handleRank()
  }

  private handleRank() {
    this.rankData = []
    this.rankOrigin.forEach((e: any) => {
      const arr = []
      arr.push(e.typeName)
      arr.push(e.quantity)
      this.rankData.push(arr)
    })
    this.initChart()
  }
  private initChart() {
    this.options.series[0].data = this.rankData
    this.chart = new Highcharts.Chart('boxChart', this.options)
  }
}
</script>
<style lang="scss" scoped>
@import '~@/styles/cockpit.scss';
.bpr2-bg {
  width: 100%;
  height: 100%;
  padding: 12px 16px 12px 30px;
  background: url('~@/assets/cockpit/bpr2-bg.png') no-repeat left center/ 99% 100%;
  position: relative;
  &::before {
    content: '';
    display: block;
    width: 20px;
    height: 103%;
    background: url('~@/assets/cockpit/bpr-bg-line.png') no-repeat 0/ 100% 100%;
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translate(0, -50%);
  }
}
.bpr2-title {
  width: 100%;
  height: 20px;
  padding: 0 0 0 6px;
  background: url('~@/assets/cockpit/bpl3-e-title-bg.png') no-repeat right center/ 99% 8px;
  font-size: 14px;
  line-height: 14px;
  color: #fff;
  position: relative;
  z-index: 1;
  > span {
    font-size: 20px !important;
    color: #fff;
  }
  &::before {
    content: '';
    width: 26px;
    height: 32px;
    background: url('~@/assets/cockpit/bpl3-e-title-left.png') no-repeat 0/ 100% 100%;
    position: absolute;
    left: -12px;
    top: -6px;
  }
}
.bpr2-chartbox {
  width: 100%;
  height: 140px;
  position: relative;
  .box-chart {
    width: 100%;
    height: 100%;
  }
  .bpr2-chart-bg {
    width: 172px;
    height: 110px;
    background: url('~@/assets/cockpit/bpr2-chart-bg.png') no-repeat 0/ 100% 100%;
    position: absolute;
    left: 20px;
    top: 30px;
  }
  .box-legend {
    position: absolute;
    top: 10px;
    right: 20px;
    > li {
      padding: 0 0 0 14px;
      font-size: 12px !important;
      line-height: 20px;
      color: #dffeff;
      position: relative;
      &::before {
        content: '';
        display: block;
        width: 4px;
        height: 4px;
        border-radius: 1px;
        transform: rotate(45deg);
        position: absolute;
        top: 8px;
        left: 0px;
      }
      &:nth-child(6n + 1) {
        &::before {
          background: #00eaff;
          box-shadow: 0 0 4px 1px #00eaff;
        }
      }
      &:nth-child(6n + 2) {
        &::before {
          background: #6dffd6;
          box-shadow: 0 0 4px 1px #6dffd6;
        }
      }
      &:nth-child(6n + 3) {
        &::before {
          background: #ffcf40;
          box-shadow: 0 0 4px 1px #ffcf40;
        }
      }
      &:nth-child(6n + 4) {
        &::before {
          background: #0095ff;
          box-shadow: 0 0 4px 1px #0095ff;
        }
      }
      &:nth-child(6n + 5) {
        &::before {
          background: #00ffaa;
          box-shadow: 0 0 4px 1px #00ffaa;
        }
      }
      &:nth-child(6n) {
        &::before {
          background: #006aff;
          box-shadow: 0 0 4px 1px #006aff;
        }
      }
    }
  }
}
</style>
